<template>
  <div class="table">
    <el-table :data="tdata" border :row-class-name="tableRowClassName" @row-click="tableLook">
      <el-table-column prop="no" label="序号" align="center" width="60">
        <template slot-scope="scope">
          <span v-if='scope.$index<9'>{{(page-1).toString()+parseInt(scope.$index+1)}}</span>
          <span v-else-if='scope.$index==9'>{{page+'0'}}</span>
          <span v-else>{{parseInt(scope.$index+1)}}</span>
        </template>
      </el-table-column>
      <el-table-column :prop="item.prop" :label="item.name" align="center" :key='index' v-for="(item,index) in thead" :width="item.width?item.width:''"
                       :fixed='item.fixed?true:false' :show-overflow-tooltip='item.tooltip?true:false'>

      </el-table-column>
      <el-table-column prop="operate" label="操作" align="center" width='120' class-name="suibian" v-if="operate">
        <template slot-scope="scope">
          <div v-if="level">
            <!-- v-if="item.prop=='reset'&&username==scope.row.cuId||item.prop=='super1'&&username=='1'||item.prop=='super'&&username=='1'||item.prop=='reset'&&username=='1'||item.prop=='confirm'&&ulevel=='0'||item.prop=='dell'||item.prop=='able'&&scope.row.status=='1'||item.prop=='undo'||item.prop=='disabled'&&scope.row.status=='0'||item.prop=='setAuth'||item.prop=='save'||item.prop=='sure'||item.prop=='del'||item.prop=='edit'||item.prop=='submitNo'&&scope.row.cu_id==username&&scope.row.temporary==1||item.prop=='editNo'&&scope.row.cu_id==username&&scope.row.isEdit=='1'||item.prop=='editAuth'&&username=='1'||item.prop=='look'||index==0&&scope.row.taskState=='2'||index==0&&scope.row.taskState=='9'||index==1&&scope.row.taskState=='10'||index==1&&scope.row.taskState=='6'" -->
            <el-button size="mini" type="text" :key="index"
                       v-for="(item,index) in operate" @click.native.prevent="deleteRow(scope.$index,item.prop)">{{item.name}}</el-button>
          </div>
          <div v-else>
            <!-- v-if="item.prop=='reset'&&username==scope.row.cuId||item.prop=='dell'&&ulevel=='0'||item.prop=='submit'||item.prop=='confirm'&&ulevel=='0'||item.prop=='able'&&scope.row.status=='1'&&scope.row.cuId==username||item.prop=='undo'&&scope.row.cuId==username||item.prop=='disabled'&&scope.row.status=='0'&&scope.row.cuId==username||item.prop=='setAuth'&&scope.row.cuId==username||item.prop=='save'&&scope.row.cuId==username||item.prop=='sure'&&scope.row.cuId==username||item.prop=='del'&&scope.row.cuId==username||item.prop=='edit'&&scope.row.cu_id==username||item.prop=='edit'&&scope.row.cuId==username||item.prop=='submitNo'&&scope.row.cu_id==username&&scope.row.temporary==1||item.prop=='editNo'&&scope.row.cu_id==username&&scope.row.isEdit=='1'||item.prop=='editAuth'&&username==scope.row.cu_id||item.prop=='look'||index==0&&scope.row.taskState=='1'&&scope.row.cuId==username||index==0&&scope.row.taskState=='0'&&scope.row.cuId==username||index==0&&scope.row.taskState=='2'&&scope.row.cuId==username||index==0&&scope.row.taskState=='9'&&scope.row.cuId==username||index==1&&scope.row.taskState=='10'&&scope.row.cuId==username||index==1&&scope.row.taskState=='6'&&scope.row.cuId==username||item.prop=='receive'||item.prop=='reject'" -->
            <el-button size="mini" type="text" :key="index"
                       v-for="(item,index) in operate" @click.native.prevent="deleteRow(scope.$index,item.prop)">{{item.name}}</el-button>
          </div>

        </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
  export default {
    name: "ttable",
    props: ["thead", "tdata", "operate", "page"],
    data() {
      return {
        username: "",
        level: '',
        ulevel: ''
      };
    },
    created() {

      this.ulevel = localStorage.getItem('ulevel')
      var b = JSON.parse(localStorage.getItem('admin2'))
      var a = this.$router.currentRoute.path.split('/')


      this.level = JSON.parse(localStorage.getItem('admin'))

      this.username = localStorage.getItem("cu_id");

    },
    methods: {
      tableRowClassName({ row, rowIndex }) {

        if (row.taskState == '2' || row.taskState == '0' || row.taskState == '1') {
          return 'warning-row';
        } else if (row.taskState == '8') {
          return 'success-row';
        } else if (row.taskState == '10') {
          return 'done-row';
        } else if (row.taskState == '4' || row.taskState == '5' || row.taskState == '6') {
          return 'over-row';
        }
        return '';

      },
      deleteRow(index, prop) {
        if (prop == "del" || prop == 'super1') {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              this.$emit("te", prop + "-" + index);
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消删除"
              });
            });
        } else {
          this.$emit("te", prop + "-" + index);
        }
      },
      tableLook(row){
        this.$emit("tlook",row);
      }
    }
  };
</script>

<style>
  .el-table .warning-row {
    background: #fe6e6e;
  }

  .el-table .success-row {
    background: #e0e0e0;
  }

  .el-table .done-row {
    background: #47ec6a;
  }

  .el-table .over-row {
    background: #b3b3b3;
  }
</style>
